﻿using System.Collections.Generic;
using DataScripter.Containers;
using DataScripter.Database;
using DataScripter.Scripting.Fluent;
using DataScripter.Scripting.InputSources;

namespace DataScripter.Scripting.ScriptDefinitions
{
    public class ScriptDefinition : IScriptDefinition
    {
        private readonly IDictionary<string, ITableScriptRequest> _scriptRequests = new Dictionary<string, ITableScriptRequest>();
        public string Name { get; private set; }
        private IContainer Container { get; set; }

        public ScriptDefinition(string name, IContainer container)
        {
            Name = name;
            Container = container;
        }

        public IDictionary<string, ITableScriptRequest> ScriptRequests
        {
            get { return _scriptRequests; }
        }

        public IFluentTableScriptRequest RequestScript(string myTableName)
        {
            IInputSource inputSource = Container.Resolve<IInputSource>();
            IDatabaseStructure databaseStructure = inputSource.Resolve<IDatabaseStructure>();
            TableScriptRequest tableScriptRequest = new TableScriptRequest(myTableName, databaseStructure, _scriptRequests.Count);
            _scriptRequests.Add(myTableName, tableScriptRequest);
            return new FluentTableScriptRequest(this, tableScriptRequest, Container);
        }

    }
}